package com.zq.ssmdemo.controller;


import com.github.pagehelper.PageInfo;
import com.zq.ssmdemo.pojo.Departments;
import com.zq.ssmdemo.service.IDepartmentsService;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 * 部门信息表 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2024-06-09
 */
@Controller
@RequestMapping("/departments")
public class DepartmentsController {


    @GetMapping("/to/departments")
    public String toDepartment(){
        return "department";
    }

    @Resource
    private IDepartmentsService departmentsService;

    @ResponseBody
    @GetMapping("/getPage/{page}/{limit}")
    public PageInfo<Departments> getPage(@PathVariable("page") Integer page,
                                         @PathVariable("limit") Integer limit) {

PageInfo<Departments> departmentsPageInfo= departmentsService.selectPage(page, limit);
        return departmentsPageInfo;
    }

    @ResponseBody
    @PostMapping("/add")
    public String add(@RequestBody Departments departments){
        System.out.println(departments);
        departmentsService.add(departments);
        return "新增成功";
    }

    @ResponseBody
    @PutMapping("/update")
    public String update(@RequestBody Departments departments){
        departmentsService.update(departments);
        return "修改成功";
    }

    @ResponseBody
    @DeleteMapping("/deleteById/{id}")
    public String delete(@PathVariable("id") Integer id){
        departmentsService.delete(id);
        return "删除成功";
    }



}
